package com.cw.jeeyt.service.impl.system;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.service.bo.system.SystemHolidayBo;
import com.cw.jeeyt.core.util.SessionUtil;
import com.cw.jeeyt.dao.intf.system.SystemHolidayDao;
import com.cw.jeeyt.dao.model.system.SystemHolidayDo;
import com.cw.jeeyt.service.converter.system.SystemHolidayConverter;
import com.cw.jeeyt.service.intf.system.SystemHolidayService;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.common.utils.SequenceTool;

/**
 * 节假日信息业务实现类
 *
 * @author chenw
 * @version 1.0.0
 */
@Service
public class SystemHolidayServiceImpl implements SystemHolidayService {

    private static final Logger logger = LoggerFactory.getLogger(SystemHolidayServiceImpl.class);
    @Autowired
    private SystemHolidayDao systemHolidayDao;//节假日信息数据库操作接口

    /**
     * 新增SystemHoliday
     *
     * @param systemHolidayBo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertSystemHoliday(SystemHolidayBo systemHolidayBo) throws Exception {

        if (systemHolidayBo == null) {
            logger.error("节假日信息为空");
            return;
        }
        SystemHolidayDo systemHoliday = SystemHolidayConverter.bo2Do(systemHolidayBo);
        systemHoliday.setId(SequenceTool.nextId());
        systemHoliday.setCreateBy(SessionUtil.getSessionUserId());
        systemHoliday.setCreateDate(new Date());
        systemHoliday.setUpdateBy(SessionUtil.getSessionUserId());
        systemHoliday.setUpdateDate(new Date());
        systemHolidayDao.insertSystemHoliday(systemHoliday);
    }

    /**
     * 更新SystemHoliday信息
     *
     * @param systemHolidayBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateSystemHoliday(SystemHolidayBo systemHolidayBo) throws Exception {

        if (systemHolidayBo == null) {
            logger.error("节假日信息为空");
            return;
        }
        SystemHolidayDo systemHoliday = SystemHolidayConverter.bo2Do(systemHolidayBo);
        systemHoliday.setUpdateBy(SessionUtil.getSessionUserId());
        systemHoliday.setUpdateDate(new Date());
        systemHolidayDao.updateSystemHoliday(systemHoliday);
    }

    /**
     * 删除SystemHoliday
     *
     * @param systemHolidayBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteSystemHoliday(SystemHolidayBo systemHolidayBo) throws Exception {
        if (systemHolidayBo == null) {
            logger.error("节假日信息为空");
            return;
        }
        systemHolidayDao.deleteSystemHoliday(SystemHolidayConverter.bo2Do(systemHolidayBo));

    }

    /**
     * 分页查询SystemHoliday
     *
     * @param systemHolidayBo
     * @param startNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SystemHolidayBo> queryByPage(SystemHolidayBo systemHolidayBo, Integer startNum, Integer pageSize)
    throws Exception {
        PageInfo<SystemHolidayDo> pageInfo = systemHolidayDao.queryByPage(SystemHolidayConverter.bo2Do(systemHolidayBo),
            startNum, pageSize);
        return new PageInfo<>(pageInfo, SystemHolidayConverter.doList2BoList(pageInfo.getList()));
    }

    /**
     * 根据主键查询SystemHoliday信息
     *
     * @param id
     * @return
     */
    @Override
    public SystemHolidayBo getSystemHolidayById(String id) throws Exception {
        return SystemHolidayConverter.do2Bo(systemHolidayDao.getSystemHolidayById(id));
    }
}
